<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // catch 方法的使用：
            // — catch方法接受一个回调函数作为实参，处理promise实例失败状态

        // catch 的返回值：
            // — catch的返回值规则与then是一样的
            // — 当catch方法里面的回调函数没有执行，或者不是回调函数，则catch会穿透



        const p1 = new Promise((resolve, reject) => {
            console.log("获取A的数据........");
            try {
                // throw new Error("网络错误A")
                setTimeout(() => {
                    resolve({
                        token: "adasdasdasfa"
                    })
                }, 3000)
            } catch (e) {
                reject(e.message)
            }
        })
        const p2 = p1.then(() => {
            return new Promise((resolve, reject) => {
                console.log("请求B1的数据.....");
                try {
                    throw new Error("网络错误B1")
                    setTimeout(() => {
                        console.log("B1的数据获取成功");
                        resolve("大成功")
                    })
                } catch (e) {
                    reject(e.message)

                }
            })
        })
        const p3 = p1.catch(reason => {
            return new Promise((resolve, reject) => {
                console.log("请求B2的数据.....");
                try {
                    throw new Error("网络错误B2")
                    setTimeout(() => {
                        console.log("B2的数据获取成功");
                        resolve("大成功")
                    })
                } catch (e) {
                    reject(e.message)
                }
            })
        })
        console.log(p1.catch());
        console.log(p1.then());
        console.log("p1", p1);
        console.log("p2", p2);
        console.log("p3", p3);
    </script>




</body>

</html>